home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / virtchk.rxx < prev    next >
Text File  |  1997-02-21  |  8KB  |  291 lines

  1. /* Check virtual dir module for SRE-FILTER. Uses contents of virtualfile
  2.   call with queue containing:
  3.        newq, newsem , SEL DEFDIR
  4.   returns
  5.        mapped_file_name  (or 0 if error )
  6.  */
  7.  
  8. parse upper arg stuff,  usequeue , USESEM, max_semwait
  9. parse upper var stuff virtualfile dlist
  10.  
  11. call pmprintf(' SRE-FILTER virtual thread: virtualfile='||virtualfile)
  12.  
  13. virtualfile=strip(virtualfile)
  14. standards=" !UPLOAD !CGI-BIN !ADDONS !HTML "  /* shorthands used in limitation list */
  15.  
  16.  
  17.  
  18. mytid=dostid()
  19. call pmprintf(' SRE-FILTER virtual thread: queue='||usequeue)
  20. call pmprintf(' SRE-FILTER virtual thread: semaphore='||usesem)
  21. call pmprintf(' SRE-FILTER virtual thread: thread id ='||mytid)
  22.  
  23. resetit:
  24. if virtualfile="" | usequeue="" | USESEM="" then do
  25.    call pmprintf('SRE-FILTER virtual thread: initialization ERROR: '||usequeue)
  26.    exit
  27. end
  28.  
  29. call set_virtual(virtualfile)
  30.  
  31.  
  32. /*
  33. do mm=1 to nvirtuals
  34.   call pmprintf(virturl.mm||' == '||virtdir.mm' -- 'virtdir.mm.limitlist)
  35. end
  36. */
  37.  
  38.  
  39. if nvirtuals=0 then do
  40.    call pmprintf(' SRE-FILTER virtual thread: Warning: No valid entries in virtual file:'||virtualfile)
  41. end
  42. else do
  43.    call pmprintf(' SRE-FILTER virtual thread:  #virtual dirs= '||nvirtuals)
  44. end
  45.  
  46.  
  47. /* Initialization now done == start waiting for requests for virtual info */
  48.  
  49. signal on error name iserror
  50. signal on syntax name iserror
  51. idid=0
  52.  
  53. bakme:
  54.  a=rxqueue('s',usequeue)
  55.  aq=queued()
  56.  if aq=0 then do
  57.     WOW=EVENTSEM_WAIT(USESEM,max_semwait)
  58.     aq=-1
  59.     if wow=640 then do
  60.          signal bakme
  61.     end
  62.     IF WOW<>0 THEN do         /* FATAL ERROR */
  63.         call pmprintf(' SRE-Filter Virtual Thread: fatal semaphore error: 'wow)
  64.         EXIT
  65.     end
  66.  end
  67.  wow=EVENTSEM_RESET(usesem)
  68.  
  69.  if aq=-1 then
  70.    if queued()=0 then signal bakme
  71.  PARSE pull isit0
  72.  
  73.  
  74.  isit0=translate(isit0,' ','000d0a09'x)
  75.  if isit0=" " then signal bakme
  76.  
  77. /* die command? */
  78.      if abbrev(isit0,'*DIE*')=1 then
  79.           exit
  80. goobs:
  81.      parse var isit0  idnum ',' newq ',' newsem ',' ISIT DEFDIR
  82.      parse var idnum idnum host_nickname
  83.      host_nickname=strip(upper(host_nickname))
  84.      isitorig=isit
  85.      if newq="" | newsem="" then do
  86.         call pmprintf(' SRE-FILTER virtual thread: missing queue or semaphore ')
  87.         exit
  88.      end
  89.      newq=upper(strip(newq)); newsem=upper(strip(newsem))
  90.      defdir=strip(defdir) ; isit=strip(isit)
  91.  
  92.     if abbrev(isit,'*RESET*') then do
  93.        newfile=defdir
  94.        if newfile<>' ' then virtualfile=newfile
  95.        call set_virtual(virtualfile)
  96.        call pmprintf(' SRE-Filter Virtual Thread:Reread virtual file: 'virtualfile)
  97.    end
  98.    else do
  99.       if isit=" " then
  100.            dog1=' 0 '
  101.       else do
  102.         isit=translate(isit,'\','/')
  103.         isit=strip(isit,'l','\')
  104.         defdir=translate(defdir,'\','/')
  105.         defdir=strip(defdir,,'\')
  106.         dog1=fig_virtual(isit,defdir,host_nickname)
  107.       end
  108.       a=rxqueue('s',newq)
  109.       push idnum ',' dog1
  110.       wow=eventsem_post(newsem)
  111.    end
  112.  
  113. signal bakme
  114.  
  115.  
  116. iserror:
  117. signal off error ; signal off syntax
  118. foo=condition('d')
  119. call pmprintf(' SRE-FIlter: error in virtual thread 'foo)
  120.  
  121. n1=queued()
  122. a=rxqueue('d',usequeue)
  123. a=rxqueue('c',usequeue)
  124. foo=eventsem_reset(usesem)
  125. a=eventsem_close(usesem)
  126. a=eventsem_create(usesem)
  127. a=rxqueue('s',newq)
  128. push idnum ', 0 '
  129. wow=eventsem_post(newsem)
  130. call pmprintf('SRE-Filter: done resetting virtual thread ')
  131. signal on error name iserror
  132. signal on syntax name iserror
  133. signal bakme
  134.  
  135. exit
  136.  
  137. /*---------------------*/
  138. fig_virtual:procedure  expose virturl. virtdir. virtsubs. virthosts.
  139.  
  140. parse UPPER arg ACTION, ddir,host_nickname
  141.  
  142. ddir2=translate(ddir,'\','/')
  143. ddir2=strip(ddir2,'t','\')||'\'
  144.  
  145. ACTION=STRIP(TRANSLATE(ACTION,'/','\'))
  146. /* check for illegal action (with .. in it) */
  147. if pos("..",action)>0 then return 0
  148.  
  149.  
  150. gotit=0 ; starat=0
  151. do ii =1 to virturl.0
  152.   if host_nickname<>virthosts.ii & virthosts.ii<>' ' then iterate
  153.  
  154.   if virtdir.ii.limitlist>' ' then do
  155.        if wordpos(ddir2,virtdir.ii.limitlist)=0 then iterate
  156.   end
  157.  
  158.   alabel=virturl.ii
  159.   if abbrev(action,upper(alabel))=1 then do
  160.          if length(alabel)< starat then iterate
  161.          starat=length(alabel)        
  162.          t1=STRIP(delstr(action,1,length(alabel)))
  163.          t1=translate(t1,'\','/')
  164.          adir=virtdir.ii
  165.          tryfile=adir||t1
  166.          if VIRTsubs.ii=1 then do 
  167.              gotit=1
  168.              iterate
  169.          end
  170.          else do
  171.             if pos('\',t1)>0 then do
  172.                  iterate                /* violation of no subdirs */
  173.             end
  174.             else do
  175.                gotit=1
  176.                iterate
  177.              end
  178.          end
  179.    end
  180. end
  181. /*  append to data dir ? */
  182.  if gotit=0 then do
  183.       t1=strip(strip(translate(ddir,'\','/')),,'\')||'\'
  184.       action=translate(action,'\','/')
  185.       action=strip(action,'l','\')
  186.       tryfile=t1||action
  187.  end
  188.  
  189.  tryfile=translate(tryfile,'\','/')
  190.  
  191. /*
  192.  if gotit=1 then
  193.     call pmprintf(" Virtual directory replacement yields: "|| tryfile)
  194. */
  195.  
  196.  return  tryfile  /* success */
  197.  
  198.  
  199.  
  200.  
  201. /* ---------------- */
  202. /* read and set up virtual dir */
  203. set_virtual:
  204. parse arg afile
  205.  
  206. nvirtuals=0 ; virturl.0=0
  207. a=fileread(afile,'ulines',,'E')   /* read it to a stem variable */
  208. foo=do_extends(1)
  209.  
  210. if a=0 then do
  211.       call pmprintf(' SRE-FILTER virtual thread: ERROR reading virtual-file: '||afile)
  212.       exit
  213. end
  214. do mm=1 to ulines.0
  215.   t1=strip(ulines.mm)
  216.   if t1="" then iterate
  217.   if abbrev(t1,';')=1 then iterate
  218.  
  219.   tm1=strip(word(t1,1)) ; ahost=' '
  220.   if right(tm1,2)='//' then do
  221.         ahost=upper(left(tm1,length(tm1)-2))
  222.         parse var t1 foo t1a t1b t1c
  223.   end
  224.   else
  225.          parse var t1 t1a t1b t1c
  226. /* fix and addd / to candidate url */
  227.   t1a=strip(translate(strip(t1a),'/','\'),,'/')||'/'
  228.  
  229.   t1b=strip(t1b)              /* subdirectories ok ? */
  230.   subok=0
  231.   if right(t1b,1)='*' then do
  232.         t1b=left(t1b,length(t1b)-1)
  233.         subok=1
  234.   end
  235.  
  236. /* fix and add \ to candidate dir */
  237.   adir=strip(translate(strip(t1b),'\','/'),'t','\')||'\'
  238.   mdir=filespec('p',adir)
  239.   mdrv=filespec('d',adir)
  240.   if drv="" then drv=filespec('d',ddir)
  241.   t1b=mdrv||mdir
  242.  
  243.   t4=" "
  244.   if t1c<>' ' then do
  245.        do mm9=1 to words(t1c)
  246.           tmp=upper(strip(word(t1c,mm9)))
  247. /* check if tmp is one of the !standard items */
  248.           imu=wordpos(tmp,standards)
  249.           if imu>0 then tmp=strip(word(dlist,imu))
  250.           tmp=translate(tmp,'\','/')
  251.           tmp=strip(tmp,'t','\')||'\'
  252.           t4=t4||' '||upper(tmp)
  253.        end
  254.   end
  255.   nvirtuals=nvirtuals+1
  256.   virtsubs.nvirtuals=subok
  257.   virturl.nvirtuals=STRIP(TRANSLATE(t1a,' ','000D0A'X))
  258.   virtdir.nvirtuals=STRIP(t1b)
  259.   virtdir.nvirtuals.limitlist=t4
  260.   virthosts.nvirtuals=ahost
  261. end
  262. virturl.0=nvirtuals
  263. return 0
  264.  
  265.                                                                              
  266.                                                                              
  267. /************/
  268. /* Redo ulines, by treating lines starting with , as continuation lines */
  269. do_extends:procedure expose ulines.
  270.  
  271. if ulines.0=0 then return
  272. isnew=1
  273. tmps.1=ulines.1
  274. do mm=2 to ulines.0
  275.    ali=strip(ulines.mm)
  276.    if abbrev(ali,',')=0 then do
  277.         isnew=isnew+1
  278.         tmps.isnew=ulines.mm
  279.     end
  280.     else do
  281.         tmps.isnew=tmps.isnew||substr(ali,2)
  282.     end
  283. end
  284. do mm=1 to isnew
  285.     ulines.mm=tmps.mm
  286. end
  287. ulines.0=isnew
  288. return 0
  289.  
  290.  
  291.